// Logging Module created by Amit Mudgal on 4/1/2014 ;
// Conscious decision to not use OTB Logging module.
package com.amex.Logging;


import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;


public class Logs  {
	// Log file would be stored in the location specified in the property file.
	public static String logFileLocation = "../DSLogs.log";
    public static void generateLog(String theLevel, String className,
         String method, String msg)
    {

         try{
     		DateFormat dateFormat = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
    		Date date = new Date();
    		String timestamp = dateFormat.format(date);
        	 File file = new File(logFileLocation);
        	 if(!file.exists()){
     			file.createNewFile();
     		}
        	//System.out.println(file.getAbsolutePath()); 
        	FileWriter fileWritter = new FileWriter(file.getAbsolutePath(),true);
 	        BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
 	        bufferWritter.write(theLevel+ "--: " + timestamp + "-- "+ className+ "." + method +" MSG:" +  msg);
 	        bufferWritter.newLine();
 	        bufferWritter.close();

         } catch (Exception e) {System.out.println("Severe Error in Logging Module");
     	File objOutFile = new File("../","DSLogs.log");
 		try {
 	    	FileWriter objFileWriter = new FileWriter(objOutFile);
 		    BufferedWriter objBufferedWriter = new BufferedWriter(objFileWriter);
 		    objBufferedWriter.write("New Log File is Created...");
 		    objBufferedWriter.close();            
 	     } catch (IOException e1) {
 		    // TODO Auto-generated catch block
 		   e1.printStackTrace();
 	       }
         }     
         }
	
}
